<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #model {
            width: 200px;
            height: 200px;
            line-height: 200px;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            border: 1px solid #000;
            text-align: center;
        }

    </style>
</head>
<body>
    <button id="open">打开弹框</button>
    <button id="close">关闭弹框</button>


    <script>

        const Model =(
            function() {
                let model = null
                return function(flag) {
                if (!model) {
                    model = document.createElement('div')
                    model.innerHTML = '我是一个全局弹框'
                    model.id = 'model'
                    document.body.appendChild(model)
                    
                }
                model.style.display = flag
                return model
            }
        }
        )()
            document.getElementById('open').addEventListener('click', () => {
                Model('block')
            })
            document.getElementById('close').addEventListener('click', () => {
                Model('none')
            })
    </script>
</body>
</html>